def getSubAryLengthList(ary):
    '''
    输入ary[]
    返回dp[]:
        dp[i]是ary[0...i]中以ary[i]结尾的最长子序列长度
    '''
    length = len(ary)
    dp = [1]*length
    for i in range(1, length):
        for j in range(i):
            if ary[i] > ary[j]:
                dp[i] = max(dp[i], dp[j]+1)
    return dp


num = int(input())
heights = list(map(int, input().split()))
leftSubAryLengthList = getSubAryLengthList(heights)
rightSubAryLengthList = getSubAryLengthList(heights[::-1])[::-1]

print(num - max(i + j - 1 for i,
      j in zip(leftSubAryLengthList, rightSubAryLengthList)))
